% p = mag2db(pspectrum(y, 20e3));
% [idx, value]=speaks_movmedian(p, length(p)/10)
[peakIndex, peakValue, peakLDR, ldrs]=speaks_movmedian(y, length(y)/10);
% figure; plot(xcorr(ldr, ceil(length(ldr)/2)));

harmon = zeros(1, length(y));
harmon(peakIndex) = peakLDR;
harmonXCor = xcorr(harmon, 'normalized');
% harmonXCor = xcorr(ldrs, 'normalized');
harmonXCor = harmonXCor(end/2:end);
harmonXCor(harmonXCor==1) = 0;
figure;
nexttile; plot(ldrs, 'o');
nexttile; plot(harmonXCor, 'o'); xlim([-10, length(harmonXCor)+10]);
%%
[peakIndex, peakValue, peakLDR]=speaks_movmedian(harmonXCor, length(harmonXCor)/10)